package com.enqualcomm.kids.component;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySqlitOpenHelper extends SQLiteOpenHelper {
    private static MySqlitOpenHelper helper;
    public static MySqlitOpenHelper getInstance(Context context){
        if (helper==null) {
            helper = new MySqlitOpenHelper(context);
        }
        return helper;
    }

    private MySqlitOpenHelper(Context context) {
        super(context, "push.db", null, 6);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //UserRead
        db.execSQL("CREATE TABLE authpass( _id integer primary key autoincrement,userid text,terminalid text,isread integer, ispass integer,imei text ,time text,date text)");
        db.execSQL("CREATE TABLE authphone( _id integer primary key autoincrement,userid text,terminalid text,isread integer, isauth integer,imei text ,time text,logid text,phone text,date text)");
        db.execSQL("CREATE TABLE ownerchange( _id integer primary key autoincrement,userid text,terminalid text,isread integer,imei text ,time text,date text)");
        db.execSQL("CREATE TABLE kickuser( _id integer primary key autoincrement,userid text,terminalid text,isread integer,imei text ,time text,date text)");

        //TerminalRead
        db.execSQL("CREATE TABLE ischager( _id integer primary key autoincrement,userid text,terminalid text,isread integer,userterminalname text,ischager integer ,time text,date text)");
        db.execSQL("CREATE TABLE islowbat( _id integer primary key autoincrement,userid text,terminalid text,isread integer,userterminalname text,islowbat integer ,time text,date text)");
        db.execSQL("CREATE TABLE pushfencing( _id integer primary key autoincrement,userid text,terminalid text,isread integer,origilng integer,origilat integer,  userterminalname text,notice integer ,time text,pushdesc text,fencingid text,fencingname text,date text)");
        db.execSQL("CREATE TABLE sosmsg( _id integer primary key autoincrement,userid text,terminalid text,isread integer,userterminalname text,origilng integer ,origilat integer,pushdesc text ,time text,date text)");

        db.execSQL("CREATE TABLE chat( _id integer primary key autoincrement,fromid text,toid text,time text,content text,status integer,isread integer,duration integer,type integer)");

        //脱落报警
        db.execSQL("CREATE TABLE detachnotice( _id integer primary key autoincrement,userid text,terminalid text,isread integer,userterminalname text,isdetached integer ,time text,date text,origilng integer,origilat integer)");
        //查询终端话费流量消息
        db.execSQL("CREATE TABLE billsms( _id integer primary key autoincrement,userid text,terminalid text,smsjson text)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (oldVersion<5){
            if (oldVersion<4){
                if (oldVersion<3){//version3 的时候，添加的kickuser表
                    //创建存储kickuser类型消息的表
                    db.execSQL("CREATE TABLE kickuser( _id integer primary key autoincrement,userid text,terminalid text,isread integer,imei text ,time text,date text)");
                }

                //创建存储聊天消息的表 version4
                db.execSQL("CREATE TABLE chat( _id integer primary key autoincrement,fromid text,toid text,time text,content text,status integer,isread integer,duration integer,type integer)");
            }

            //创建存储脱落报警信息的表 version5
            db.execSQL("CREATE TABLE detachnotice( _id integer primary key autoincrement,userid text,terminalid text,isread integer,userterminalname text,isdetached integer ,time text,date text,origilng integer,origilat integer)");
        }
        db.execSQL("CREATE TABLE billsms( _id integer primary key autoincrement,userid text,terminalid text,smsjson text)");
//        db.execSQL("CREATE TABLE newauthphone( _id integer primary key autoincrement,userid text,terminalid text,isread integer, isauth integer,imei text ,time text,logid text,phone text,date text,authuserid text,authuserkey text)");

    }
}

